#include "sock5server.hpp"
#include "logger.hpp"
#include "sock5client.hpp"
#include "sock5clientmgr.hpp"

namespace oraysock5 {
Sock5Server::Sock5Server(std::shared_ptr<IPAddress> listen_addr)
    : ListenEvent(listen_addr)
{
    LOG_INFO << "服务器sock5启动 [ip:" << listen_addr->ip() << ":" << listen_addr->port() << "]";
}
Sock5Server::~Sock5Server()
{
    LOG_INFO << "服务器sock5关闭 [ip:" << listenaddr()->ip() << ":" << listenaddr()->port() << "]";
}

std::weak_ptr<AcceptNewFd> Sock5Server::accept_newfd(
    std::shared_ptr<IPAddress> remoteAddr, std::shared_ptr<EventBuffer> iobuf)
{
    std::shared_ptr<Sock5Client> cli(new Sock5Client(remoteAddr, listenaddr(), iobuf));
    Singleton<Sock5ClientMgr>::instance().add(iobuf->fd(), cli);
    return cli;
}

}
